package com.mcxx.modules.miniSalvation.order.service.read;

import com.mcxx.common.exception.BizException;
import com.mcxx.constant.DictConstant;
import com.mcxx.formulcount.param.FormulCountParam;
import com.mcxx.modules.base.service.read.DictionaryReadService;
import com.mcxx.modules.miniSalvation.order.dao.read.StandardHistoryReadDao;
import com.mcxx.modules.miniSalvation.order.dto.SalvationStandardDTO;
import com.mcxx.modules.miniSalvation.order.entity.StandardEntity;
import com.mcxx.modules.miniSalvation.order.entity.StandardHistoryEntity;
import com.mcxx.modules.system.dao.read.SalvationRuleReadDao;
import com.mcxx.modules.system.param.StandardParam;
import com.mcxx.util.Constant;
import com.yinhai.ta404.core.restservice.requestbean.PageParam;
import com.yinhai.ta404.core.restservice.resultbean.Page;
import com.yinhai.ta404.core.security.vo.UserAccountVo;
import com.yinhai.ta404.core.service.BaseService;
import com.yinhai.ta404.core.transaction.annotation.TaTransactional;
import com.yinhai.ta404.module.dict.entity.TaDictPo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service("standardHistoryReadService")
@TaTransactional(readOnly = true)
public class StandardHistoryReadService extends BaseService {

    @Autowired
    private StandardHistoryReadDao standardHistoryReadDao;
    @Autowired
    private SalvationRuleReadDao salvationRuleReadDao;
    @Autowired
    private DictionaryReadService dictionaryReadService;


    public Page getStandardHistoryList(StandardParam param, PageParam pageParam) {
        standardHistoryReadDao.beginPager(pageParam);
        List<StandardHistoryEntity> list = standardHistoryReadDao.getStandardHistoryList(param);
        return standardHistoryReadDao.endPager(list);
    }


    public StandardHistoryEntity getByParam(StandardParam standardParam) {
        return standardHistoryReadDao.getByParam(standardParam);
    }


    public List<StandardHistoryEntity> querySalvationByPid(String pId){return standardHistoryReadDao.querySalvationByPid(pId);}


    public Map<String, Object> getSalvationDetail(String id){
        Map<String, Object> rstMap = new HashMap<>();

        StandardParam standardParam = new StandardParam();
        standardParam.setId(id);
        StandardHistoryEntity salvationStandard = this.getByParam(standardParam);
        rstMap.put("salvationStandard", salvationStandard);


        List<StandardHistoryEntity> childStandardList =  this.querySalvationByPid(id);
        if(!childStandardList.isEmpty()){
            rstMap.put("childStandardList", childStandardList);
        }

        return rstMap;
    }

    public StandardEntity querySalvationStandard(Map<String, Object> param) {
        return standardHistoryReadDao.querySalvationStandard(param);
    }


    public double getStandardMoney(String welfareId, String areaCode, String businessType, String type){
        return standardHistoryReadDao.getStandardMoney(welfareId, areaCode, businessType, type);
    }


    public List<StandardHistoryEntity> getStandardHisByWelfareId(String welfareId) {
        return standardHistoryReadDao.selectStandardHisByWelfareId(welfareId);
    }


    public List<StandardHistoryEntity> selectStandardHisByStandardId(String standardId, Integer status) {
        return standardHistoryReadDao.selectStandardHisByStandardId(standardId, status);
    }
}
